(function (window, document, $) {
	$('#validCode').val(8888)
	$(document).on('click', '#login_btn', function () {
		//check
		if ($('#username').val() == '') {
			alertify.error('请输入用户名');
			$('#username').focus();
			return false;
		} else if ($('#password').val() == '') {
			alertify.error('请输入密码');
			$('#password').focus();
			return false;
		} else if ($('#validCode').val() == '') {
			alertify.error('请输入验证码');
			$('#validCode').focus();
			return false;
		}
		submitLoading();
		location.href = '/workshop?key=employee_manage';
		return false;
		$.ajax({
			url: "/login",
			data: $('#loginForm').serialize(),
			contentType: "application/x-www-form-urlencoded;charset=UTF-8",
			type: "POST",
			success: function (data) {
				if (data.code && data.code != 'O000000') {
					alertify.error(data.message);
					$('.reload-vify').click();
					$('[name=validCode]').val('8888');
					if (data.message && data.message.indexOf('验证码') > -1) {
						$('[name=validCode]').focus();
					}
					submitLoading();
				} else {
					//location.href = '/workshop?key=home';
					location.href = '/workshop?key=nation_report';
				}

			},
			error: function (error) {
				if (error.responseText) {
					alertify.error(error.responseText);
				} else {
					alertify.error('网络异常请重试');
				}
				submitLoading();
			}
		})
	});

	let loginForm = document.getElementById("loginForm");
	loginForm.onkeypress = function (e) {
		let e = window.event || e;
		if (e.keyCode == 13 || e.which == 13) {
			$('#login_btn').click();
			return false;
		}
	};
	/**
	 * 随机用户名
	 */
	function randomName() {
		$('#username').val('wwl');
		$('#password').val('123456');
		$('#validCode').focus();
	}
	if (isDebug && store.get('_userName') == 'wwl') {
		randomName();
	}
})(window, document, jQuery);

function submitLoading() {
	if ($('.spinner').hasClass('hide')) {
		$('.spinner').removeClass('hide');
		$('#login_btn .text').addClass('hide');

		$('#login_btn').attr('disabled', true);
	} else {
		$('.spinner').addClass('hide');
		$('#login_btn .text').removeClass('hide');
		$('#login_btn').attr('disabled', false);
	}
}